/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nio;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

/**
 *
 * @author Administrator
 */
public class ConsoleFileVisitor extends SimpleFileVisitor<Path>{
    
    @Override
    public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException{
    
        printSpace(path);
        System.out.println(path.getFileName());
        return FileVisitResult.CONTINUE;
    }
    
    @Override
    public FileVisitResult visitFile(Path path, BasicFileAttributes attr) {
    
        printSpace(path);
        System.out.println(path.getFileName());
        return FileVisitResult.CONTINUE;
    }
    
    @Override
    public FileVisitResult visitFileFailed(Path file, IOException e) {
    
        System.err.println(e);
        return FileVisitResult.CONTINUE;
    }
    
    private void printSpace(Path path){
    
        System.out.println(path.getNameCount() * 2 + "s");
    }
}
